package org.stragma.apply.signatures

import scala.collection.mutable._

import aterm._
import org.stragma.apply.signatures.Apply._
import org.stragma.apply.signatures.ApplyExtensions._

/*
 * These conversions are needed to compensate for the fact that Stratego
 * is not strongly typed unlike Scala.
 */
object Conversions {

	implicit def ConvertTArgTypeToATerm (arg0 : TArgType) : ATerm = 
		TArgTypeToATerm(arg0)

	implicit def ConvertTArgTypeToTType (arg0 : TArgType) : TType = 
		ATermToTType(TArgTypeToATerm(arg0))

	implicit def ConvertTArgTypeToTVar (arg0 : TArgType) : TVar = 
		ATermToTVar(TArgTypeToATerm(arg0))

	implicit def ConvertTExpToATerm (arg0 : TExp) : ATerm = 
		TExpToATerm(arg0)

	implicit def ConvertATermToTEExp (arg0 : ATerm) : TEExp = 
		ATermToTEExp(arg0)

	implicit def ConvertTEExpToTExp (arg0 : TEExp) : TExp = 
		ATermToTExp(TEExpToATerm(arg0))

	implicit def ConvertListTRangeToTRangeList (arg0 : List[TRange]) : ListTRangeToTRangeList = 
		ListTRangeToTRangeList(arg0)

	implicit def ConvertTRangeListToTExpList (arg0 : TRangeList) : TExpList = 
		ATermToTExpList(TRangeListToATerm(arg0))

	implicit def ConvertListTExpToTExpList (arg0 : List[TExp]) : ListTExpToTExpList = 
		ListTExpToTExpList(arg0)

	implicit def ConvertTVarToTType (arg0 : TVar) : TType = 
		TVarToTType(arg0)

	implicit def ConvertTTypeToTArgType (arg0 : TType) : TArgType = 
		TTypeToTArgType(arg0)	

	implicit def ConvertVarToTArgType (arg0 : Var) : TArgType = 
		TTypeToTArgType(TVarToTType(arg0))

	implicit def ConvertArrayToTArgType (arg0 : Array) : TArgType = 
		TTypeToTArgType(arg0)

	implicit def ConvertATermToTVar (arg0 : ATerm) : TVar = 
		ATermToTVar(arg0)

	implicit def ConvertTVarToTScalarVar (arg0 : TVar) : TScalarVar = 
		TVarToTScalarVar(arg0)

	implicit def ConvertTScalarVarToTExp (arg0 : TScalarVar) : TExp = 
		TScalarVarToTExp(arg0)

	implicit def ConvertTVarToTExp (arg0 : TVar) : TExp = 
		TScalarVarToTExp(TVarToTScalarVar(arg0))

	implicit def ConvertVarExtensionToTExp (arg0 : VarExtension) : TExp = 
		TScalarVarToTExp(TVarToTScalarVar(arg0))

	implicit def ConvertCAssignToTEExp (arg0 : CAssign) : TEExp = 
		TExpToTEExp(arg0)
	
	implicit def ConvertLtToTEExp (arg0 : Lt) : TEExp = 
		TExpToTEExp(arg0)
	
	implicit def ConvertTStatmentsToStatements (arg0 : TStatements) : Statements = 
		arg0.asInstanceOf[Statements]
	
	implicit def ConvertTStatmentsToListOfTStatement (arg0 : TStatements) : List[TStatement] = 
		arg0.asInstanceOf[Statements].arg0
	
	implicit def ConvertTStatementToListOfTStatement (arg0 : TStatement) : List[TStatement] = 
		List(arg0)
	
	implicit def ConvertListTExpToTStatements (arg0 : List[TExp]) : TStatements = {
		
		// Step 1 convert, each TExp to a TStatement
		val listOfStatements : ListBuffer[TStatement] = ListBuffer[TStatement]()
		
		arg0 foreach {
			exp =>
				val texpAsATerm = TExpToATerm (exp)
				val atermAsTStatement = ATermToTStatement (texpAsATerm)
				listOfStatements += atermAsTStatement
		}
		
		// Step 2 then convert the List[TStatements] to TStatements
		Statements (listOfStatements.toList)
	} 
}